const axios = require("axios"); //引入axios
const main_base_URL = 'https://minireport.seedsufe.com';

export default {
  server: {
    port: 3000, // default: 3000
    host: '0.0.0.0' // default: localhost
  },
  // Global page headers: https://go.nuxtjs.dev/config-head
  sitemap: {
    hostname: main_base_URL
  },
  env: {
    main_base_URL
  },
  head: {
    title: "【方案查一查】全网实战方案获取工具",
    htmlAttrs: {
      lang: "cn",
    },
    meta: [
      { charset: "utf-8" },
      { hid: 'description', name: 'description', content: '方案查一查是一款超好用的全网实战方案获取工具，超过50个细分行业，超过10万份方案，由上海俟德教育科技有限公司出品。' },
      { hid: 'keywords', name: 'keywords', content: '方案,策划方案,调查研究报告,行业分析报告,行业数据报告,股票报告,券商研报,管理咨询' },
      { name: 'og:description', content: '方案查一查是一款超好用的全网实战方案获取工具，超过50个细分行业，超过10万份方案，由上海俟德教育科技有限公司出品。' },
      { name: 'og:site_name', content: '方案查一查' },
      { name: 'og:locale', content: 'cn' },
      { name: 'og:url', content: 'https://report.seedsufe.com' },
      { name: "viewport", content: "width=device-width, initial-scale=1" },
      { name: "360-site-verification", content: "528b8bc8c0bd6c267b6fcf3559fc1647" },
    ],
    link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }],
  },
  pwa: {
    meta: {
      title: '方案查一查',
      author: '俟德教育',
    },
    manifest: {
      name: '方案查一查',
      short_name: '方案查一查',
      lang: 'cn',
    },
  },
  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
    "element-ui/lib/theme-chalk/index.css",
    "normalize.css/normalize.css",
    "@/assets/css/style.less",
  ],
  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [
    { src: "~/plugins/element-ui", ssr: true },
    { src: "~/plugins/vuex-persistedstate", ssr: false },
    { src: "~/plugins/pdf", ssr: false },
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    // Simple usage
    "@nuxtjs/router",

    // With options
    [
      "@nuxtjs/router",
      {
        /* module options */
      },
    ],
  ],
  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    // Simple usage
    "cookie-universal-nuxt",
    // With options
    ["cookie-universal-nuxt", { alias: "cookiz" }],
    // "@nuxtjs/router",
    "@nuxtjs/dayjs",
    "@nuxtjs/style-resources",
    "@nuxtjs/sitemap",
    '@nuxtjs/pwa',
  ],

  dayjs: {
    locales: ["en", "ja"],
    defaultLocale: "en",
  },

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    extractCSS: { allChunks: true },
    transpile: [/^element-ui/, /^vue-qart/, /^js-cookie/, /^wxmp-rsa/],
  },
  styleResources: {
    less: ["@/assets/css/var.less", "@/assets/css/style.less"],
  },
  sitemap: {
    path: '/sitemap.xml',
    hostname: "https://report.seedsufe.com/",
    cacheTime: 60 * 60 * 24, //  更新频率，只在 generate: false有用
    gzip: true, // 生成 .xml.gz 压缩的 sitemap
    generate: false, // 允许使用 nuxt generate 生成
    exclude: [
      "/user",
      "/admin"
    ],
    defaults: {
      changefreq: "daily",
      priority: 1,
      lastmod: new Date(),
    },

    routes(callback) {
      //通过axios获取到服务器内文章的id，及标签，或者其他想要动态生成到.xml内容链接
      axios
        .all([
          axios.get(
            "https://minireport.seedsufe.com/api/v2/seo/sitemap/getLast2WeekOfReports",
          ), //获取最近报告
          axios.get(
            "https://minireport.seedsufe.com/api/v2/seo/sitemap/getLast1MonthOfRecommendReports",
          ), //获取推荐报告
          axios.get(
            "https://minireport.seedsufe.com/api/v2/fileInsight/getList?page=1&pageSize=100",
          ), //获取洞察

        ])
        .then(
          axios.spread(function (recentReports, recommendReports, insights) {
            // console.log(recentReports);
            // console.log("articles--------------------------------------------");
            // console.log(recommendReports);
            // console.log("tags--------------------------------------------");

            let now = new Date();
            now.setHours(
              now.getHours(),
              now.getMinutes() - now.getTimezoneOffset()
            );

            //创建一个数组，存放要生成链接
            var importantPaths = [
              "/", //这里的'/'等于前面的hostname
              "/index",
              "/aboutVip",
              "/insight/index"
            ];

            let indexRoutes = importantPaths.map((item) => {
              return {
                url: item,
                changefreq: "daily",
                priority: 0.9,
                lastmod: now.toISOString(),
              };
            });

            let recentRoutes = recentReports.data.data.map((item) => {
              return {
                url: item.url,
                changefreq: "daily",
                priority: 0.8,
                lastmod: item.createDateText,
              };
            });

            let recommendRoutes = recommendReports.data.data.map((item) => {
              return {
                url: item.url,
                changefreq: "always",
                priority: 1.0,
                lastmod: item.createDateText,
              };
            });

            let insightRoutes = insights.data.data.data.map((item) => {
              return {
                url: 'insight/detail?id=' + item.id,
                changefreq: "always",
                priority: 1.0,
                lastmod: item.create_time_format,
              };
            });
            // console.log(indexRoutes);
            //最终将所有链接返回，生成sitemap.xml
            callback(null, indexRoutes.concat(insightRoutes).concat(recommendRoutes).concat(recentRoutes));
          })
        );
    },
  },
};
